#include "SMPPStructures.hpp"

using namespace smpp::pdu;

DestAddress::DestAddress(const quint8 nTON,const quint8 nNPI, 
const CoctetString &nAddress):
_DestFlag(DestFlag::SME_ADDRESS),_TON(nTON),_NPI(nNPI),
_Address_DistrListName(nAddress){}

DestAddress::DestAddress(const CoctetString &nDistrListName):
_DestFlag(DestFlag::DISTR_LIST_NAME),_TON(0),_NPI(0),
_Address_DistrListName(nDistrListName){}

DestAddress::DestAddress(const DestAddress &nDestAddress):
_DestFlag(nDestAddress.getDestFlag()),
_TON(nDestAddress.getTON()),_NPI(nDestAddress.getNPI()),
_Address_DistrListName(nDestAddress.getAddressOrDistrListName()){}

const bool DestAddress::operator ==(const DestAddress &nDestAddress) const{
	return (_DestFlag == nDestAddress.getDestFlag() &&
			_TON == nDestAddress.getTON() && _NPI == 
			nDestAddress.getNPI() &&
			_Address_DistrListName == 
			nDestAddress.getAddressOrDistrListName());
}

const bool DestAddress::operator !=(const DestAddress &nDestAddress) const{
	return !operator == (nDestAddress);
}

DestAddress &DestAddress::operator =(const DestAddress &nDestAddress){
	if(*this == nDestAddress)
		return *this;
	_DestFlag = nDestAddress.getDestFlag();
	_TON = nDestAddress.getTON();
	_NPI = nDestAddress.getNPI();
	_Address_DistrListName = nDestAddress.getAddressOrDistrListName();
	return *this;
}

const quint8 DestAddress::getDestFlag() const{
	return _DestFlag;
}

void DestAddress::setAddress(const quint8 nTON,
	const quint8 nNPI,const CoctetString &nAddress){
		_DestFlag = DestFlag::SME_ADDRESS;
		_TON = nTON;
		_NPI = nNPI;
		_Address_DistrListName = nAddress;
}

void DestAddress::setDistrListName(
	const CoctetString &nDistrListName){
		_DestFlag = DestFlag::DISTR_LIST_NAME;
		_TON = 0;
		_NPI = 0;
		_Address_DistrListName = nDistrListName;
}

const quint8 DestAddress::getTON() const{
	return _TON;
}

const quint8 DestAddress::getNPI() const{
	return _NPI;
}

const CoctetString &DestAddress::getAddressOrDistrListName() const{
	return _Address_DistrListName;
}

const quint8 DestAddress::getLength() const{
	quint8 length(1);
	if(_DestFlag == DestFlag::SME_ADDRESS)
		length += 2;
	length += _Address_DistrListName.size();
	return length;
}

UnsuccessSME::UnsuccessSME(const quint8 nDestAddrTON, 
const quint8 nDestAddrNPI,
const CoctetString &nDestinationAddr,
const quint32 nErrorStatusCode):
_DestAddrTON(nDestAddrTON),
_DestAddrNPI(nDestAddrNPI),
_DestinationAddr(nDestinationAddr),
_ErrorStatusCode(nErrorStatusCode){}

UnsuccessSME::UnsuccessSME(const UnsuccessSME &nUnsuccessSME):
_DestAddrTON(nUnsuccessSME.getDestAddrTON()),
_DestAddrNPI(nUnsuccessSME.getDestAddrNPI()),
_DestinationAddr(nUnsuccessSME.getDestinationAddr()),
_ErrorStatusCode(nUnsuccessSME.getErrorStatusCode()){}

const bool UnsuccessSME::operator ==(
	const UnsuccessSME &nUnsuccessSME) const{
	return (_DestAddrTON == nUnsuccessSME.getDestAddrTON() && 
			_DestAddrNPI == nUnsuccessSME.getDestAddrNPI() && 
			_DestinationAddr == nUnsuccessSME.getDestinationAddr() && 
			_ErrorStatusCode == nUnsuccessSME.getErrorStatusCode());
}

const bool UnsuccessSME::operator !=(
	const UnsuccessSME &nUnsuccessSME) const{
	return !this->operator==(nUnsuccessSME);
}

UnsuccessSME &UnsuccessSME::operator =(
	const UnsuccessSME &nUnsuccessSME){
	if(*this == nUnsuccessSME)
		return *this;
	_DestAddrTON = nUnsuccessSME.getDestAddrTON();
	_DestAddrNPI = nUnsuccessSME.getDestAddrNPI();
	_DestinationAddr = nUnsuccessSME.getDestinationAddr(); 
	_ErrorStatusCode = nUnsuccessSME.getErrorStatusCode();
	return *this;
}

void UnsuccessSME::setDestAddrTON(const quint8 nDestAddrTON){
	_DestAddrTON = nDestAddrTON;
}

const quint8 UnsuccessSME::getDestAddrTON() const{
	return _DestAddrTON;
}

void UnsuccessSME::setDestAddrNPI(const quint8 nDestAddrNPI){
	_DestAddrNPI = nDestAddrNPI;
}

const quint8 UnsuccessSME::getDestAddrNPI() const{
	return _DestAddrNPI;
} 

void UnsuccessSME::setDestinationAddr(
	const CoctetString &nDestinationAddr){
	_DestinationAddr = nDestinationAddr;
}

const CoctetString &UnsuccessSME::getDestinationAddr() const{
	return _DestinationAddr;
} 

void UnsuccessSME::setErrorStatusCode(const quint32 nErrorStatusCode){
	_ErrorStatusCode = nErrorStatusCode;
}

const quint32 UnsuccessSME::getErrorStatusCode() const{
	return _ErrorStatusCode;
}

const quint8 UnsuccessSME::getLength() const{
	quint8 length(6 + _DestinationAddr.size());
	return length;
}
